﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DataLib.DBUtility;
using System.Collections;
using log4net;

namespace DataLib.DAL
{
	/// <summary>
	/// 数据访问类:BarCode
	/// </summary>
	public partial class BarCode
	{
        ILog log = log4net.LogManager.GetLogger("Logger");
        //log.Info("数据插入不成功，操作人员 " + Common.ConfigHelper.username);
        public BarCode()
        { }
        #region  BasicMethod

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("id", "BarCode");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int? id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from BarCode");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
			};
            parameters[0].Value = id;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(DataLib.Model.BarCode model)
        {
            if (model.goodscode.Length > 7)
            {
                model.busscode = model.goodscode.Substring(0, 7);
                
            }
            else
            {
                model.busscode = model.goodscode;
            }
            
            
            if (model.goodscode.Substring(0,1) == "D" || model.goodscode.Substring(0,1) == "H")
            {
                model.stype = "原料库";
            }
            else if (model.goodscode.Substring(0, 1) == "B")
            {
                model.stype = "半成品库";
            }
            else
            {
                model.stype = "成品库";
            }

            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into BarCode(");
            strSql.Append("loadnumid,cjoid,ParmentID,loadnumv,barcodevalue,goodscode,goodsname,remark,storagetype,storageid,status,gwt,tare1,tare2,nwt,qty,comeunder,packageno,isLocak,InStrorageID,OutStrorageID,StorageArea,Attribute,stroageNo,rubbishcode,rubbishtype,rdh,plateid,plateno,boxcount,createdate,isdel_out,sealno,barbelong,bargraphic,goodsid,outdate,insno,outsno,clearmonth,cumname,projectcode,projectname,cumshortname,bussCode,SType)");
            strSql.Append(" values (");
            strSql.Append("@loadnumid,@cjoid,@ParmentID,@loadnumv,@barcodevalue,@goodscode,@goodsname,@remark,@storagetype,@storageid,@status,@gwt,@tare1,@tare2,@nwt,@qty,@comeunder,@packageno,@isLocak,@InStrorageID,@OutStrorageID,@StorageArea,@Attribute,@stroageNo,@rubbishcode,@rubbishtype,@rdh,@plateid,@plateno,@boxcount,@createdate,@isdel_out,@sealno,@barbelong,@bargraphic,@goodsid,@outdate,@insno,@outsno,@clearmonth,@cumname,@projectcode,@projectname,@cumshortname,@bussCode,@SType)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@loadnumid", SqlDbType.Int,4),
					new SqlParameter("@cjoid", SqlDbType.Int,4),
					new SqlParameter("@ParmentID", SqlDbType.Int,4),
					new SqlParameter("@loadnumv", SqlDbType.NVarChar,30),
					new SqlParameter("@barcodevalue", SqlDbType.NVarChar,35),
					new SqlParameter("@goodscode", SqlDbType.NVarChar,30),
					new SqlParameter("@goodsname", SqlDbType.NVarChar,30),
					new SqlParameter("@remark", SqlDbType.NVarChar,200),
					new SqlParameter("@storagetype", SqlDbType.Int,4),
					new SqlParameter("@storageid", SqlDbType.Int,4),
					new SqlParameter("@status", SqlDbType.Int,4),
					new SqlParameter("@gwt", SqlDbType.Decimal,9),
					new SqlParameter("@tare1", SqlDbType.Decimal,9),
					new SqlParameter("@tare2", SqlDbType.Decimal,9),
					new SqlParameter("@nwt", SqlDbType.Decimal,9),
					new SqlParameter("@qty", SqlDbType.Int,4),
					new SqlParameter("@comeunder", SqlDbType.NVarChar,30),
					new SqlParameter("@packageno", SqlDbType.NVarChar,30),
					new SqlParameter("@isLocak", SqlDbType.Bit,1),
					new SqlParameter("@InStrorageID", SqlDbType.Int,4),
					new SqlParameter("@OutStrorageID", SqlDbType.Int,4),
					new SqlParameter("@StorageArea", SqlDbType.NVarChar,30),
					new SqlParameter("@Attribute", SqlDbType.NVarChar,30),
					new SqlParameter("@stroageNo", SqlDbType.NVarChar,30),
					new SqlParameter("@rubbishcode", SqlDbType.NVarChar,30),
					new SqlParameter("@rubbishtype", SqlDbType.NVarChar,30),
					new SqlParameter("@rdh", SqlDbType.NVarChar,30),
					new SqlParameter("@plateid", SqlDbType.Int,4),
					new SqlParameter("@plateno", SqlDbType.NVarChar,30),
					new SqlParameter("@boxcount", SqlDbType.Int,4),
					new SqlParameter("@createdate", SqlDbType.DateTime),
					new SqlParameter("@isdel_out", SqlDbType.Int,4),
					new SqlParameter("@sealno", SqlDbType.NVarChar,30),
					new SqlParameter("@barbelong", SqlDbType.VarChar,20),
					new SqlParameter("@bargraphic", SqlDbType.VarChar,20),
					new SqlParameter("@goodsid", SqlDbType.Int,4),
					new SqlParameter("@outdate", SqlDbType.DateTime),
					new SqlParameter("@insno", SqlDbType.VarChar,30),
					new SqlParameter("@outsno", SqlDbType.VarChar,30),
					new SqlParameter("@clearmonth", SqlDbType.VarChar,10),
					new SqlParameter("@cumname", SqlDbType.VarChar,200),
					new SqlParameter("@projectcode", SqlDbType.VarChar,100),
					new SqlParameter("@projectname", SqlDbType.VarChar,200),
					new SqlParameter("@cumshortname", SqlDbType.VarChar,200),
					new SqlParameter("@bussCode", SqlDbType.VarChar,12),
					new SqlParameter("@SType", SqlDbType.VarChar,20)};
            parameters[0].Value = model.loadnumid;
            parameters[1].Value = model.cjoid;
            parameters[2].Value = model.ParmentID;
            parameters[3].Value = model.loadnumv;
            parameters[4].Value = model.barcodevalue;
            parameters[5].Value = model.goodscode;
            parameters[6].Value = model.goodsname;
            parameters[7].Value = model.remark;
            parameters[8].Value = model.storagetype;
            parameters[9].Value = model.storageid;
            parameters[10].Value = model.status;
            parameters[11].Value = model.gwt;
            parameters[12].Value = model.tare1;
            parameters[13].Value = model.tare2;
            parameters[14].Value = model.nwt;
            parameters[15].Value = model.qty;
            parameters[16].Value = model.comeunder;
            parameters[17].Value = model.packageno;
            parameters[18].Value = model.isLocak;
            parameters[19].Value = model.InStrorageID;
            parameters[20].Value = model.OutStrorageID;
            parameters[21].Value = model.StorageArea;
            parameters[22].Value = model.Attribute;
            parameters[23].Value = model.stroageNo;
            parameters[24].Value = model.rubbishcode;
            parameters[25].Value = model.rubbishtype;
            parameters[26].Value = model.rdh;
            parameters[27].Value = model.plateid;
            parameters[28].Value = model.plateno;
            parameters[29].Value = model.boxcount;
            parameters[30].Value = model.createdate;
            parameters[31].Value = model.isdel_out;
            parameters[32].Value = model.sealno;
            parameters[33].Value = model.barbelong;
            parameters[34].Value = model.bargraphic;
            parameters[35].Value = model.goodsid;
            parameters[36].Value = model.outdate;
            parameters[37].Value = model.insno;
            parameters[38].Value = model.outsno;
            parameters[39].Value = model.clearmonth;
            parameters[40].Value = model.cumname;
            parameters[41].Value = model.projectcode;
            parameters[42].Value = model.projectname;
            parameters[43].Value = model.cumshortname;
            parameters[44].Value = model.busscode;
            parameters[45].Value = model.stype;
            object obj = null;
            string username = Common.ConfigHelper.username;
            try
            {
                obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
              log.Info(username + "新插入Barcode:" + model.barcodevalue );
            }
            catch (Exception ex)
            {
                log.Error(username +"执行条码插入失败：" + ex.Message);
            }
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(DataLib.Model.BarCode model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update BarCode set ");
            strSql.Append("loadnumid=@loadnumid,");
            strSql.Append("cjoid=@cjoid,");
            strSql.Append("ParmentID=@ParmentID,");
            strSql.Append("loadnumv=@loadnumv,");
            strSql.Append("barcodevalue=@barcodevalue,");
            strSql.Append("goodscode=@goodscode,");
            strSql.Append("goodsname=@goodsname,");
            strSql.Append("remark=@remark,");
            strSql.Append("storagetype=@storagetype,");
            strSql.Append("storageid=@storageid,");
            strSql.Append("status=@status,");
            strSql.Append("gwt=@gwt,");
            strSql.Append("tare1=@tare1,");
            strSql.Append("tare2=@tare2,");
            strSql.Append("nwt=@nwt,");
            strSql.Append("qty=@qty,");
            strSql.Append("comeunder=@comeunder,");
            strSql.Append("packageno=@packageno,");
            strSql.Append("isLocak=@isLocak,");
            strSql.Append("InStrorageID=@InStrorageID,");
            strSql.Append("OutStrorageID=@OutStrorageID,");
            strSql.Append("StorageArea=@StorageArea,");
            strSql.Append("Attribute=@Attribute,");
            strSql.Append("stroageNo=@stroageNo,");
            strSql.Append("rubbishcode=@rubbishcode,");
            strSql.Append("rubbishtype=@rubbishtype,");
            strSql.Append("rdh=@rdh,");
            strSql.Append("plateid=@plateid,");
            strSql.Append("plateno=@plateno,");
            strSql.Append("boxcount=@boxcount,");
            strSql.Append("createdate=@createdate,");
            strSql.Append("isdel_out=@isdel_out,");
            strSql.Append("sealno=@sealno,");
            strSql.Append("barbelong=@barbelong,");
            strSql.Append("bargraphic=@bargraphic,");
            strSql.Append("goodsid=@goodsid,");
            strSql.Append("outdate=@outdate,");
            strSql.Append("insno=@insno,");
            strSql.Append("outsno=@outsno,");
            strSql.Append("clearmonth=@clearmonth,");
            strSql.Append("cumname=@cumname,");
            strSql.Append("projectcode=@projectcode,");
            strSql.Append("projectname=@projectname,");
            strSql.Append("cumshortname=@cumshortname,");
            strSql.Append("bussCode=@bussCode,");
            strSql.Append("SType=@SType");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@loadnumid", SqlDbType.Int,4),
					new SqlParameter("@cjoid", SqlDbType.Int,4),
					new SqlParameter("@ParmentID", SqlDbType.Int,4),
					new SqlParameter("@loadnumv", SqlDbType.NVarChar,30),
					new SqlParameter("@barcodevalue", SqlDbType.NVarChar,35),
					new SqlParameter("@goodscode", SqlDbType.NVarChar,30),
					new SqlParameter("@goodsname", SqlDbType.NVarChar,30),
					new SqlParameter("@remark", SqlDbType.NVarChar,200),
					new SqlParameter("@storagetype", SqlDbType.Int,4),
					new SqlParameter("@storageid", SqlDbType.Int,4),
					new SqlParameter("@status", SqlDbType.Int,4),
					new SqlParameter("@gwt", SqlDbType.Decimal,9),
					new SqlParameter("@tare1", SqlDbType.Decimal,9),
					new SqlParameter("@tare2", SqlDbType.Decimal,9),
					new SqlParameter("@nwt", SqlDbType.Decimal,9),
					new SqlParameter("@qty", SqlDbType.Int,4),
					new SqlParameter("@comeunder", SqlDbType.NVarChar,30),
					new SqlParameter("@packageno", SqlDbType.NVarChar,30),
					new SqlParameter("@isLocak", SqlDbType.Bit,1),
					new SqlParameter("@InStrorageID", SqlDbType.Int,4),
					new SqlParameter("@OutStrorageID", SqlDbType.Int,4),
					new SqlParameter("@StorageArea", SqlDbType.NVarChar,30),
					new SqlParameter("@Attribute", SqlDbType.NVarChar,30),
					new SqlParameter("@stroageNo", SqlDbType.NVarChar,30),
					new SqlParameter("@rubbishcode", SqlDbType.NVarChar,30),
					new SqlParameter("@rubbishtype", SqlDbType.NVarChar,30),
					new SqlParameter("@rdh", SqlDbType.NVarChar,30),
					new SqlParameter("@plateid", SqlDbType.Int,4),
					new SqlParameter("@plateno", SqlDbType.NVarChar,30),
					new SqlParameter("@boxcount", SqlDbType.Int,4),
					new SqlParameter("@createdate", SqlDbType.DateTime),
					new SqlParameter("@isdel_out", SqlDbType.Int,4),
					new SqlParameter("@sealno", SqlDbType.NVarChar,30),
					new SqlParameter("@barbelong", SqlDbType.VarChar,20),
					new SqlParameter("@bargraphic", SqlDbType.VarChar,20),
					new SqlParameter("@goodsid", SqlDbType.Int,4),
					new SqlParameter("@outdate", SqlDbType.DateTime),
					new SqlParameter("@insno", SqlDbType.VarChar,30),
					new SqlParameter("@outsno", SqlDbType.VarChar,30),
					new SqlParameter("@clearmonth", SqlDbType.VarChar,10),
					new SqlParameter("@cumname", SqlDbType.VarChar,200),
					new SqlParameter("@projectcode", SqlDbType.VarChar,100),
					new SqlParameter("@projectname", SqlDbType.VarChar,200),
					new SqlParameter("@cumshortname", SqlDbType.VarChar,200),
					new SqlParameter("@bussCode", SqlDbType.VarChar,12),
					new SqlParameter("@SType", SqlDbType.VarChar,20),
					new SqlParameter("@id", SqlDbType.Int,4)};
            parameters[0].Value = model.loadnumid;
            parameters[1].Value = model.cjoid;
            parameters[2].Value = model.ParmentID;
            parameters[3].Value = model.loadnumv;
            parameters[4].Value = model.barcodevalue;
            parameters[5].Value = model.goodscode;
            parameters[6].Value = model.goodsname;
            parameters[7].Value = model.remark;
            parameters[8].Value = model.storagetype;
            parameters[9].Value = model.storageid;
            parameters[10].Value = model.status;
            parameters[11].Value = model.gwt;
            parameters[12].Value = model.tare1;
            parameters[13].Value = model.tare2;
            parameters[14].Value = model.nwt;
            parameters[15].Value = model.qty;
            parameters[16].Value = model.comeunder;
            parameters[17].Value = model.packageno;
            parameters[18].Value = model.isLocak;
            parameters[19].Value = model.InStrorageID;
            parameters[20].Value = model.OutStrorageID;
            parameters[21].Value = model.StorageArea;
            parameters[22].Value = model.Attribute;
            parameters[23].Value = model.stroageNo;
            parameters[24].Value = model.rubbishcode;
            parameters[25].Value = model.rubbishtype;
            parameters[26].Value = model.rdh;
            parameters[27].Value = model.plateid;
            parameters[28].Value = model.plateno;
            parameters[29].Value = model.boxcount;
            parameters[30].Value = model.createdate;
            parameters[31].Value = model.isdel_out;
            parameters[32].Value = model.sealno;
            parameters[33].Value = model.barbelong;
            parameters[34].Value = model.bargraphic;
            parameters[35].Value = model.goodsid;
            parameters[36].Value = model.outdate;
            parameters[37].Value = model.insno;
            parameters[38].Value = model.outsno;
            parameters[39].Value = model.clearmonth;
            parameters[40].Value = model.cumname;
            parameters[41].Value = model.projectcode;
            parameters[42].Value = model.projectname;
            parameters[43].Value = model.cumshortname;
            parameters[44].Value = model.busscode;
            parameters[45].Value = model.stype;
            parameters[46].Value = model.id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int? id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from BarCode ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
			};
            parameters[0].Value = id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from BarCode ");
            strSql.Append(" where id in (" + idlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DataLib.Model.BarCode GetModel(int? id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 id,loadnumid,cjoid,ParmentID,loadnumv,barcodevalue,goodscode,goodsname,remark,storagetype,storageid,status,gwt,tare1,tare2,nwt,qty,comeunder,packageno,isLocak,InStrorageID,OutStrorageID,StorageArea,Attribute,stroageNo,rubbishcode,rubbishtype,rdh,plateid,plateno,boxcount,createdate,isdel_out,sealno,barbelong,bargraphic,goodsid,outdate,insno,outsno,clearmonth,cumname,projectcode,projectname,cumshortname,bussCode,SType from BarCode ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
			};
            parameters[0].Value = id;

            DataLib.Model.BarCode model = new DataLib.Model.BarCode();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DataLib.Model.BarCode DataRowToModel(DataRow row)
        {
            DataLib.Model.BarCode model = new DataLib.Model.BarCode();
            if (row != null)
            {
                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.id = int.Parse(row["id"].ToString());
                }
                if (row["loadnumid"] != null && row["loadnumid"].ToString() != "")
                {
                    model.loadnumid = int.Parse(row["loadnumid"].ToString());
                }
                if (row["cjoid"] != null && row["cjoid"].ToString() != "")
                {
                    model.cjoid = int.Parse(row["cjoid"].ToString());
                }
                if (row["ParmentID"] != null && row["ParmentID"].ToString() != "")
                {
                    model.ParmentID = int.Parse(row["ParmentID"].ToString());
                }
                if (row["loadnumv"] != null)
                {
                    model.loadnumv = row["loadnumv"].ToString();
                    if (model.loadnumv.Substring(0, 2) == "86")
                    {
                        Model.LoadNum lm = new LoadNum().GetLoadID(model.loadnumv);
                        if (lm != null)
                        {
                            model.cumcode = lm.cumcode;
                            model.cumname = lm.cumname;
                        }
                    }
                }
                if (row["barcodevalue"] != null)
                {
                    model.barcodevalue = row["barcodevalue"].ToString();
                }
                if (row["goodscode"] != null)
                {
                    model.goodscode = row["goodscode"].ToString();
                }
                if (row["goodsname"] != null)
                {
                    model.goodsname = row["goodsname"].ToString();
                }
                if (row["remark"] != null)
                {
                    model.remark = row["remark"].ToString();
                }
                if (row["storagetype"] != null && row["storagetype"].ToString() != "")
                {
                    model.storagetype = int.Parse(row["storagetype"].ToString());
                }
                if (row["storageid"] != null && row["storageid"].ToString() != "")
                {
                    model.storageid = int.Parse(row["storageid"].ToString());
                }
                if (row["status"] != null && row["status"].ToString() != "")
                {
                    model.status = int.Parse(row["status"].ToString());
                }
                if (row["gwt"] != null && row["gwt"].ToString() != "")
                {
                    model.gwt = decimal.Parse(row["gwt"].ToString());
                }
                if (row["tare1"] != null && row["tare1"].ToString() != "")
                {
                    model.tare1 = decimal.Parse(row["tare1"].ToString());
                }
                if (row["tare2"] != null && row["tare2"].ToString() != "")
                {
                    model.tare2 = decimal.Parse(row["tare2"].ToString());
                }
                if (row["nwt"] != null && row["nwt"].ToString() != "")
                {
                    model.nwt = decimal.Parse(row["nwt"].ToString());
                }
                if (row["qty"] != null && row["qty"].ToString() != "")
                {
                    model.qty = int.Parse(row["qty"].ToString());
                }
                if (row["comeunder"] != null)
                {
                    model.comeunder = row["comeunder"].ToString();
                }
                if (row["packageno"] != null)
                {
                    model.packageno = row["packageno"].ToString();
                }
                if (row["isLocak"] != null && row["isLocak"].ToString() != "")
                {
                    if ((row["isLocak"].ToString() == "1") || (row["isLocak"].ToString().ToLower() == "true"))
                    {
                        model.isLocak = true;
                    }
                    else
                    {
                        model.isLocak = false;
                    }
                }
                if (row["InStrorageID"] != null && row["InStrorageID"].ToString() != "")
                {
                    model.InStrorageID = int.Parse(row["InStrorageID"].ToString());
                }
                if (row["OutStrorageID"] != null && row["OutStrorageID"].ToString() != "")
                {
                    model.OutStrorageID = int.Parse(row["OutStrorageID"].ToString());
                }
                if (row["StorageArea"] != null)
                {
                    model.StorageArea = row["StorageArea"].ToString();
                }
                if (row["Attribute"] != null)
                {
                    model.Attribute = row["Attribute"].ToString();
                }
                if (row["stroageNo"] != null)
                {
                    model.stroageNo = row["stroageNo"].ToString();
                }
                if (row["rubbishcode"] != null)
                {
                    model.rubbishcode = row["rubbishcode"].ToString();
                }
                if (row["rubbishtype"] != null)
                {
                    model.rubbishtype = row["rubbishtype"].ToString();
                }
                if (row["rdh"] != null)
                {
                    model.rdh = row["rdh"].ToString();
                }
                if (row["plateid"] != null && row["plateid"].ToString() != "")
                {
                    model.plateid = int.Parse(row["plateid"].ToString());
                }
                if (row["plateno"] != null)
                {
                    model.plateno = row["plateno"].ToString();
                }
                if (row["boxcount"] != null && row["boxcount"].ToString() != "")
                {
                    model.boxcount = int.Parse(row["boxcount"].ToString());
                }
                if (row["createdate"] != null && row["createdate"].ToString() != "")
                {
                    model.createdate = DateTime.Parse(row["createdate"].ToString());
                }
                if (row["isdel_out"] != null && row["isdel_out"].ToString() != "")
                {
                    model.isdel_out = int.Parse(row["isdel_out"].ToString());
                }
                if (row["sealno"] != null)
                {
                    model.sealno = row["sealno"].ToString();
                }
                if (row["barbelong"] != null)
                {
                    model.barbelong = row["barbelong"].ToString();
                }
                if (row["bargraphic"] != null)
                {
                    model.bargraphic = row["bargraphic"].ToString();
                }
                if (row["goodsid"] != null && row["goodsid"].ToString() != "")
                {
                    model.goodsid = int.Parse(row["goodsid"].ToString());
                }
                if (row["outdate"] != null && row["outdate"].ToString() != "")
                {
                    model.outdate = DateTime.Parse(row["outdate"].ToString());
                }
                if (row["insno"] != null)
                {
                    model.insno = row["insno"].ToString();
                }
                if (row["outsno"] != null)
                {
                    model.outsno = row["outsno"].ToString();
                }
                if (row["clearmonth"] != null)
                {
                    model.clearmonth = row["clearmonth"].ToString();
                }
                if (row["cumname"] != null)
                {
                    model.cumname = row["cumname"].ToString();
                }
                if (row["projectcode"] != null)
                {
                    model.projectcode = row["projectcode"].ToString();
                }
                if (row["projectname"] != null)
                {
                    model.projectname = row["projectname"].ToString();
                }
                if (row["cumshortname"] != null)
                {
                    model.cumshortname = row["cumshortname"].ToString();
                }
                if (row["bussCode"] != null)
                {
                    model.busscode = row["bussCode"].ToString();
                }
                if (row["SType"] != null)
                {
                    model.stype = row["SType"].ToString();
                }
            }

            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,loadnumid,cjoid,ParmentID,loadnumv,barcodevalue,goodscode,goodsname,remark,storagetype,storageid,status,gwt,tare1,tare2,nwt,qty,comeunder,packageno,isLocak,InStrorageID,OutStrorageID,StorageArea,Attribute,stroageNo,rubbishcode,rubbishtype,rdh,plateid,plateno,boxcount,createdate,isdel_out,sealno,barbelong,bargraphic,goodsid,outdate,insno,outsno,clearmonth,cumname,projectcode,projectname,cumshortname,bussCode,SType ");
            strSql.Append(" FROM BarCode ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" id,loadnumid,cjoid,ParmentID,loadnumv,barcodevalue,goodscode,goodsname,remark,storagetype,storageid,status,gwt,tare1,tare2,nwt,qty,comeunder,packageno,isLocak,InStrorageID,OutStrorageID,StorageArea,Attribute,stroageNo,rubbishcode,rubbishtype,rdh,plateid,plateno,boxcount,createdate,isdel_out,sealno,barbelong,bargraphic,goodsid,outdate,insno,outsno,clearmonth,cumname,projectcode,projectname,cumshortname,bussCode,SType ");
            strSql.Append(" FROM BarCode ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM BarCode ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.id desc");
            }
            strSql.Append(")AS Row, T.*  from BarCode T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "BarCode";
            parameters[1].Value = "id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod


	}
}
